package com.jiaai.web.zfp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.jms.Destination;

/**
 * class_name:ZHbProducer
 * describe:-------------->消息队列的producer
 * create_user:张昉平
 * create_date:2017/12/28
 * create_date:18:57
 */
@Service("producer")
public class JMSProducer {

    @Autowired
    private JmsMessagingTemplate jms;

    public Integer publishHb(Destination destination, String json){
        Message<String> ms = MessageBuilder.withPayload(json).build();
        Message<?> obj = jms.sendAndReceive(destination, ms);
        String res = (String) obj.getPayload();
        return Integer.parseInt(res);
    }

    public String snatchHb(Destination destination, String json){
        Message<String> ms = MessageBuilder.withPayload(json).build();
        Message<?> obj = jms.sendAndReceive(destination, ms);
        String res = (String) obj.getPayload();
        return res;
    }

    public void completeHb(Destination destination, String liveId){
        jms.convertAndSend(destination, liveId);
    }

    public void runOrStopRobot(Destination destination, String msg){
        jms.convertAndSend(destination, msg);
    }
}
